button4 2.2.1
Loading...
Searching...
No Matches
button4


Button 4 Click

Button 4 Click demo application is developed using the NECTO Studio, ensuring compatibility with mikroSDK's open-source libraries and tools. Designed for plug-and-play implementation and testing, the demo is fully compatible with all development, starter, and mikromedia boards featuring a mikroBUS™ socket.


Click Library

  • Author : Stefan Filipovic
  • Date : Mar 2025.
  • Type : GPIO type

Software Support

Example Description

This example demonstrates the use of the Button 4 Click board by initializing the device and detecting the button state changes. It logs whether the button is pressed (active) or released (reset).

Example Libraries

  • MikroSDK.Board
  • MikroSDK.Log
  • Click.Button4

Example Key Functions

  • button4_cfg_setup This function initializes Click configuration structure to initial values.
    void button4_cfg_setup(button4_cfg_t *cfg)
    Button 4 configuration object setup function.
    Button 4 Click configuration object.
    Definition button4.h:112
  • button4_init This function initializes all necessary pins and peripherals used for this Click board.
    err_t button4_init ( button4_t *ctx, button4_cfg_t *cfg );
    err_t button4_init(button4_t *ctx, button4_cfg_t *cfg)
    Button 4 initialization function.
    Button 4 Click context object.
    Definition button4.h:102
  • button4_get_out_pin This function returns the OUT pin logic state.
    uint8_t button4_get_out_pin ( button4_t *ctx );
    uint8_t button4_get_out_pin(button4_t *ctx)
    Button 4 get out pin function.

Application Init

Initializes the logger and the Button 4 Click driver.

void application_init ( void )
{
log_cfg_t log_cfg;
button4_cfg_t button4_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
// Click initialization.
button4_cfg_setup( &button4_cfg );
if ( DIGITAL_OUT_UNSUPPORTED_PIN == button4_init( &button4, &button4_cfg ) )
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
log_info( &logger, " Application Task " );
}
#define BUTTON4_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition button4.h:91
void application_init(void)
Definition main.c:34
#define MIKROBUS_POSITION_BUTTON4
Definition main.c:28

Application Task

Monitors the button state and logs whether the button is active (pressed) or reset (released) when a state change is detected.

void application_task ( void )
{
static uint8_t button_state_old = BUTTON4_BUTTON_RESET;
uint8_t button_state = button4_get_out_pin ( &button4 );
if ( button_state_old != button_state )
{
button_state_old = button_state;
if ( BUTTON4_BUTTON_ACTIVE == button_state )
{
log_printf ( &logger, " BUTTON ACTIVE\r\n\n" );
}
else
{
log_printf ( &logger, " BUTTON RESET\r\n\n" );
}
}
}
#define BUTTON4_BUTTON_ACTIVE
Button 4 button state setting.
Definition button4.h:72
#define BUTTON4_BUTTON_RESET
Definition button4.h:73
void application_task(void)
Definition main.c:64

Application Output

This Click board can be interfaced and monitored in two ways:

  • Application Output - Use the "Application Output" window in Debug mode for real-time data monitoring. Set it up properly by following this tutorial.
  • UART Terminal - Monitor data via the UART Terminal using a USB to UART converter. For detailed instructions, check out this tutorial.

Additional Notes and Information

The complete application code and a ready-to-use project are available through the NECTO Studio Package Manager for direct installation in the NECTO Studio. The application code can also be found on the MIKROE GitHub account.